package com.titaniume.java;

/**
 *@program: JavaSenior
 *@description: 案例：创建3个窗口卖票，总票数为100张，使用继承Runable接口的方式
 *
 * 存在线程安全 待解决
 *
 *
 *@author: renfei.huang
 *@create: 2021-09-29 09:50
 */
public class WindowTest1 {

    public static void main(String[] args) {

        //用的一个对象 票数不需要static 还是100
        Window1 window1 = new Window1();

        Thread t1 = new Thread(window1);
        Thread t2 = new Thread(window1);
        Thread t3 = new Thread(window1);

        t1.start();
        t2.start();
        t3.start();
    }

}


class  Window1 implements  Runnable{


    private int ticket = 100;

    @Override
    public void run() {
        while (true){
            if(ticket >0){
                System.out.println(Thread.currentThread().getName() + "：卖票，票号为:"+ticket);
                ticket --;
            }else {
                break;
            }
        }
    }
}